function post(url, data, cb, error_cb) {
    if (data == null) {
        data = {}
    }
    var token = cookie("user_token");

    if (token != null) {
        data.token = token
    }
    $.ajax({
        url: url_p+url,
        type: "POST",
        data: data,
        dataType: "json",
        success: function (data) {
            if(data.error_code==0){
                cb(data.result)
            }else{
                if(data.error_code==1){
                    if(error_cb==null){
                        toast(data.message)
                    }else{
                        error_cb(data.message)
                    }
                }
                else if(data.error_code==301){
                    tologin()
                }
                else if(data.error_code==302){
                    toreg()
                }
                else{
                    error_cb(data.message,data.error_code)
                }

            }
        },
        error: function (msg) {
            var message="网络异常"
            var errcode=msg.status;
            if(errcode==500 ||errcode==404){
                message="服务器异常"
            }
            if(error_cb!=null){
                error_cb(message,-1)
            }
            toast(message)
        }
    })
}
String.prototype.format = function (args) {
    if (arguments.length > 0) {
        var result = this;
        if (arguments.length == 1 && typeof(args) == "object") {
            for (var key in args) {
                var reg = new RegExp("({" + key + "})", "g");
                result = result.replace(reg, args[key]);
            }
        } else {
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] == undefined) {
                    return "";
                } else {
                    var reg = new RegExp("({[" + i + "]})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
        return result;
    } else {
        return this;
    }
}
var $_GET = (function () {
    var url = window.document.location.href.toString();
    var u = url.split("?");
    if (typeof(u[1]) == "string") {
        u = u[1].split("&");
        var get = {};
        for (var i in u) {
            var j = u[i].split("=");
            get[j[0]] = j[1];
        }
        return get;
    } else {
        return {};
    }
})();


function local(key, value) {
    if (value == "del") {
        localStorage.removeItem(key);
    }
    else if (value != null) {
        localStorage.setItem(key, value);
    } else {
        var val = localStorage.getItem(key);
        val = val == null ? undefined : val
        return val;
    }

}

function cookie(key, value, day) {
    var op = {path:"/"}
    if (day == null) {
        day = 7
    }
    if (value == "del") {
        op['expires'] = -1
        $.cookie(key, null, op);
        return
    }
    else if (value != null) {

        op['expires'] = day


        $.cookie(key, value, op);
        return
    } else {
        return $.cookie(key);
    }
}
function dellist(i, list) {
    var newlist = [];
    for (var j in list) {
        if (i != j) {
            newlist.push(list[j])
        }
    }
    return newlist
}


function log(l) {
    try{
        console.log(l)
    }catch (e){

    }
}
function getformdata(id) {
    var list = {}
    var data = $("#" + id).serializeArray();
    for(var i = 0; i < data.length; i++) {
        list[data[i].name] = data[i].value
    }
    return list
}
